package com.blackitheima3.polymorphic;

public class TestCatAndDog {
    public static void main(String[] args) {
        getAnimal(new CatC());
        getAnimal(new DogD());
    }
    public static void getAnimal(AnimalA animal){
        animal.eat();
        if(animal instanceof DogD){
            DogD d= (DogD) animal;
            d.watchHome();
        }
    }
}
class AnimalA{
    public void eat(){
        System.out.println("动物吃东西!");
    }
}

class CatC extends AnimalA{
    public void eat(){
        System.out.println("猫吃鱼!");
    }
}
class DogD extends AnimalA {
    public void eat(){
        System.out.println("狗吃肉!");
    }
    public void watchHome(){
        System.out.println("小狗看门");
    }
}